package net.xiduth.game.npc.combat.impl;

import net.xiduth.game.Animation;
import net.xiduth.game.Entity;
import net.xiduth.game.ForceTalk;
import net.xiduth.game.Graphics;
import net.xiduth.game.npc.NPC;
import net.xiduth.game.npc.combat.CombatScript;
import net.xiduth.game.npc.combat.NPCCombatDefinitions;
import net.xiduth.utils.Misc;

/**
 * 
 * @author Taylor<Axter> Under name Elixrr
 */
public class FungalRodent extends CombatScript {

	@Override
	public Object[] getKeys() {
		return new Object[] { "Fungal rodent" };
	}

	@Override
	public int attack(NPC npc, Entity target) {
		final NPCCombatDefinitions defs = npc.getCombatDefinitions();
		int size = npc.getSize();
		int distanceX = target.getX() - npc.getX();
		int distanceY = target.getY() - npc.getY();
		if (distanceX < size && distanceX > -1 && distanceY < size
				&& distanceY > -1) {
			delayHit(
					npc,
					0,
					target,
					getRegularHit(
							npc,
							getRandomMaxHit(npc, defs.getMaxHit(),
									NPCCombatDefinitions.MELEE, target)));
		}
		int attackStyle = Misc.getRandom(4);
		if (attackStyle == 0 || attackStyle == 1) {
			if (distanceX > size || distanceX < -1 || distanceY > size
					|| distanceY < -1)
				npc.setNextAnimation(new Animation(15514));
			delayHit(
					npc,
					1,
					target,
					getMagicHit(
							npc,
							getRandomMaxHit(npc, 650,
									NPCCombatDefinitions.MELEE, target)));
			return defs.getAttackDelay();
		} // if they're far away, the beast will mage them
		else {
			if (Misc.random(4) == 0) {
				npc.setNextForceTalk(new ForceTalk("*Sigh*"));
			}
			npc.setNextAnimation(new Animation(15516));
			npc.setNextGraphics(new Graphics(2014));
			delayHit(
					npc,
					1,
					target,
					getMagicHit(
							npc,
							getRandomMaxHit(npc, 650,
									NPCCombatDefinitions.MAGE, target)));
			return defs.getAttackDelay();
		}
	}
}
